﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BLL;
using DLL;
using ENUMS;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void ibtnLanding_Click(object sender, ImageClickEventArgs e)
    {
        //验证验证码是否正确
        if (txtVali.Text != (string)Session["valiNum"])
        {
            ShowMessage("验证码错误！");
            return;
        }
        int stuId = -1;
        landInfo land;
        //如果账号是否数字型字符串则为学生登陆否则为其他登陆
        if (int.TryParse(txtUid.Text, out stuId))
        {
            //验证用户信息并记录返回值
            land= landing_BLL.ValiUser(txtUid.Text, txtPwd.Text, identity.student);
            //如果验证通过则保存登陆信息并跳转页面
            if (land.UserId != null)
            {
                Session.Timeout = 150;
                Session["landInfo"] = land;
                Response.Redirect("manaPage.aspx");
            }
        }
        else
        {
            //验证用户信息并记录返回值
            land = landing_BLL.ValiUser(txtUid.Text, txtPwd.Text, identity.worker);
            //如果验证通过则保存登陆信息并跳转页面
            if (land.UserId != null)
            {
                Session["landInfo"] = land;
                Response.Redirect("manaPage.aspx");
            }
        }
    }
    
    /// <summary>
    /// 显示消息
    /// </summary>
    /// <param name="msg">消息内容</param>
    protected void ShowMessage(string msg)
    {
        RegisterStartupScript("msg", "<script type='text/javascript' language='javascript'>alert('" + msg + "')</script>");
    }
}
